/**
 * Created by Administrator on 2016/9/16 0016.
 */
const mongoose = require("./connection.js");
var async = require("async");

var Schema = mongoose.Schema;
var bookInfoSchema = new Schema({
    webIndex:String,
    bookName:  String,
    author: String,
    updateDate:   String,
    updateChapter: String,
    description: String,
    chapterList:[{
        index:Number,
        chapterName:String,
        chapterHref:String
    }]
});



//静态方法
//根据书名查找某本书
bookInfoSchema.statics.getBookByBookName = function(bookName,callback){
    BookInfo.findOne({bookName:bookName}).exec(callback);
}
//根据书ID查找某本书
bookInfoSchema.statics.getBookByBookId = function(bookId,callback){
    BookInfo.findOne({_id:bookId}).exec(callback);
}
//书名列表
bookInfoSchema.statics.getBookNameList = function(callback){
    BookInfo.find({}).select("bookName").exec(callback);
}
//---------------------------------------------------------------------------------

//数据更新
bookInfoSchema.methods.update = function(callback){
    var bookinfo = this;
    var bookName = bookinfo.bookName;
    BookInfo.findOneAndUpdate({bookName:bookName},bookinfo,null,cb);
};

var BookInfo = mongoose.model('BookInfo', bookInfoSchema);
module.exports = BookInfo;

